<?php
namespace Home\Controller;
use Common\Controller\HomeBaseController; 
class IndexController extends HomeBaseController {
    public function index(){
    
    	$data=$this->_lists(3);
    	$this->pubsubcomm();
    	$anli=$this->_lists(1,2);
    	$this->assign("anli",$anli);
    	
    	$this->assign("data",$data);
       $this->display(":index");
    }
    public function addfens()
    {
    	
    	$this->display(":addfens");
    }
    public function server()
    {
    	
    	$data=$this->typesofAc(3,30);
    	$this->pubsubcomm();
    	$anli=$this->_lists(1,2);

    	$this->assign("data",$data);
    	$this->assign("anli",$anli);
    	
    	$this->display(":server");	
    
    }
    public function Subscribe()
    {
    	$data=$this->typesofAc(2,30);
    	$this->pubsubcomm();
    	$anli=$this->_lists(1,2);
    	
    	$this->assign("data",$data);
    	$this->assign("anli",$anli);
    	 
    	$this->display(":subscribe");
    }
    public function firend()
    {
    	
    	$this->display(":friend");
    }
    public function advantage()
    {
    	$this->display(":advantage");	
    
    }
    public function cooperate()
    {
    	$this->display(":cooperate");
    }

    private  function _lists($type=1,$num=10){
    	$where["pid"]=$type;
    	$Fore=M("Foreport");
    	$data=$Fore->where($where)
    	->limit($num)
    	->order("list DESC")->select();
    	foreach($data as $key=>$val)
    	{
    		if(!empty($val["details"]))
    		{
    			$data[$key]['details']=unserialize($val["details"]);
    		}
    	}
    	return $data;
    }
    

    public function pubsubcomm()
    {
    	$comm=M("PubAssort")->order("listorder desc")->getField("id,t_name");
    	$this->assign("comm",$comm);
    
    }
    protected function friendcomm()
    {
    	$comm=M("circleType")->order("listorder desc")->getField("id,t_name");
    	$this->assign("comm",$comm);
    
    }
    protected function typesofAc($type,$num)
    {
    	$newdata=array();
    	$data=$this->_lists($type,$num);
    	foreach($data as $key=>$val)
    	{
    		if(!isset($newdata[$val["types"]]))
    		{	
    		  $newdata[$val["types"]]=$val;
    		}
    	}
    	return $newdata;	
    }
    
    
    
}